home *** CD-ROM | disk | FTP | other *** search
/ 8bitfiles.net/archives / archives.tar / archives / compuserve-file-archive / 05 Programming / BFRTH3.DOC < prev    next >
Text File  |  2019-04-13  |  11KB  |  198 lines

  1. *hd3:Blazin' Forth Documentation,System Information,-#-
  2. *cn1;Input and Output*cn0
  3.  
  4. Blazin' Forth supports all the necessary words to handle any peripheral device on the serial bus, or on the IEEE bus, if you have an extension card like the BUSCARD II. I left certain definitions out deliberately, so that users who require them can define them as they like.
  5.  
  6. Higher Level Words.
  7.  
  8. The system supports I/O redirection of output to a printer. The words PRINTER and NOPRINTER will open a channel to a 1526 printer, connected as device # 4. After executing PRINTER , all output will be directed to the printer. NOPRINTER will redirect output to the screen. Both PRINTER and NOPRINTER are DEFERed (see DEFER for more information), to make it easy for you to alter them, if you need to, without having to recompile the system. #LP is a constant which contains the current device number of the systems line printer. As currently configured, PRINTER sends a control code to the printer which turns on paging, and NOPRINTER sends a control code which turns paging off (these codes are for the 1526 printer). If your printer uses different control codes, or doesn't require them, you will probably want to revector these words. I would suggest you examine the definitions of LP and NLP for an example of how to write such words in Forth. In particular, it is important to have PRINTER set the user variable PRINTING? to TRUE, and NOPRINTER should reset PRINTING? to false.
  9.  
  10. The word DOS" has been provided to allow you to send commands to the disk drive from Forth. Any command which is recognized by the 1541 or a compatible drive may be sent using this word. As an example:
  11. DOS" N0:DISKNAME,ID"
  12. will format a disk in drive 0. Note that there must be a space between the " and the command.
  13.  
  14. To read the disks error channel, you can use the word ?DISC . Note that ?DISC will only display the message if there is an error.
  15.  
  16. MOUNT
  17. MOUNT initializes the virtual disk operating system of Forth. It *must* be used before any word which accesses the disk. Note that you only need to use this word once, at the start of a session, and not before every LIST or LOAD command. (You must reissue it if you use RESTART, or if you change disks during a session.) Note that the disk light will remain on while the system is in operation. This is normal, and should not cause you a second thought.
  18.  
  19. If you require information on accessing standard CBM disk files, please see the appendix. These are the only words required in normal usage of the system.
  20. *fp0
  21. *cn1;Extensions to the 83 Standard*cn0
  22.  
  23. BOOLEANS:
  24.  
  25. Blazin' Forth contains the following boolean tests which are not part of the 83 standard:
  26.  
  27. 0<>  Leaves a true flag if top of stack is non-zero.
  28.  
  29. 0>   Leaves a true flag if top of stack is positive.
  30.  
  31. <>   Leaves a true flag if top of stack is not equal to second element of stack.
  32. D>   Leaves a true flag if the second double number is greater than the doublenumber on the top of the stack.
  33.  
  34. CONDITIONAL EXECUTION
  35.  
  36. BEGIN...AGAIN is included. It is the same as
  37.  
  38. BEGIN .... FALSE UNTIL
  39.  
  40. Or, in other words, an infinite loop.
  41.  
  42. Multiple WHILEs are supported by Blazin' Forth. For example:
  43.  
  44. BEGIN <action> <condition> WHILE <action> <condition> WHILE <action> REPEAT
  45.  
  46. Note that you are not limited to only two whiles, this is simply an example.
  47.  
  48. LOOPING
  49.  
  50. Forth-83 loops are very fast, make the older /LOOP unnecessary, and are generally much improved over the earlier Forth Loops. However, when the loop index is equal to the loop limit, the loop will not execute once, but 64k times. For occasions when this is not wanted, Blazin' Forth provides ?DO . ?DO will not allow the loop to be executed if the limit and index are equal. For example:
  51.  
  52. : LOOP1   ?DO I . LOOP ;
  53.  
  54. Does the same thing as:
  55.  
  56. : LOOP2  2DUP <> IF DO I . LOOP ELSE 2DROP THEN ;
  57.  
  58. Note that the first is much shorter, and also much faster. Of course, ?DO will also work with +LOOP, just like DO does.
  59.  
  60. Forth-83's LEAVE is also changed from earlier LEAVEs. Forth-83's LEAVE jumps immediately to the word after LOOP or +LOOP, while the older LEAVE would continue through the remainder of the loop, exiting at the LOOP or +LOOP. Blazin' Forth contains a word, ?LEAVE which can be quicker and a real code saver when all you need to do is scram. For example:
  61.  
  62. : EXIT1 10 0 DO  I . 5 = ?LEAVE LOOP ;
  63.  
  64. Will cause the same effect as:
  65.  
  66. : EXIT2 10 0 DO  I . 5 = IF LEAVE THEN LOOP ;
  67.  
  68. Note that ?LEAVE takes less room, and is also quicker, than the second alternative.
  69.  
  70. Interactive Extensions
  71.  
  72. ?KEY ( -- char )
  73. This word works just like the standard KEY , but while KEY will wait for a keypress, ?KEY reads the keyboard, and returns the ASCII value of the key pressed, or a null (0) if no key was pressed.
  74.  
  75. PAUSE ( -- flag)
  76. This word is basically a souped up ?TERMINAL. ?TERMINAL will return a TRUE flag if the stop key is pressed, and false otherwise. PAUSE will do the same thing, but, additionally, if any key other than the stop key has been pressed, it will halt execution and wait for the next key. Note that although PAUSE handles the waiting, it is up to the calling word to process the flag.
  77.  
  78. JOYSTICK ( port# -- direction )
  79. Requires a value on the stack, which should be either 0 or 1. If 0, joystick port 1 will be read, If 1, joystick port 2 will be read. Joystick leaves a value on the top of the stack which indicates the direction of the joystick. -1 means the stick is centered, 0 is up, with values increasing to the right, so 1 is forward and up, 2 is to the right, etc. Note that if these values are multiplied by 45 the result is suitable for SETH (see graphics extensions).
  80.  
  81. JOYBUTTON ( port# -- flag )
  82. Leaves true on the stack if the joy stick button at the appropriate port is depressed, otherwise leaves false. Requires the same values on the stack as JOYSTICK.
  83.  
  84. PADDLE ( paddle# -- value )
  85. Requires a number from 0 to 3 on the stack which specifies the paddle. Leaves a value between 0 and 255 on the stack, depending on the setting of the appropriate paddle. Note that these words may also be used to read other devices, such as a Koala Pad.
  86.  
  87. PADDLEBUTTON ( paddle# -- flag)
  88. Leaves a true or a false on the stack, depending on whether or not the addressed button has been depressed. Requires the same values as PADDLE.
  89.  
  90. JIFFY! ( doublenumber -- )
  91. Used to set the 64's Jiffy Clock. Requires a double number on the stack.
  92.  
  93. JIFFY@ ( -- doublenumber )
  94. Used to read the 64's Jiffy Clock. Leaves a double number on the stack. Note that 1 Jiffy = 1/60 of a second.
  95.  
  96. JIFFIES ( n -- )
  97. Requires a single number on the stack. JIFFIES will cause a wait of n jiffies before continuing.
  98.  
  99. CURSOR ( x y -- )
  100. Positions the cursor at the x y coordinates on the top of the stack.
  101.  
  102. CURSORPOS ( -- x y )
  103. Leaves the current position of the cursor ( x and y ) on the top of the stack.
  104.  
  105.  
  106. CONSTANTS
  107. Blazin' Forth has precompiled the following constants.
  108.  
  109. 0 1 2 3
  110. These simply leave their value on the stack.
  111.  
  112. TRUE
  113. Leaves the value for TRUE (-1) on the stack.
  114. FALSE
  115. Leaves the value for FALSE (0) on the stack.
  116.  
  117. VARIABLES
  118. Blazin' Forth has the following variables which may be of use to you:
  119.  
  120. #LINE
  121. A user variable which contains the number of times the word CR has been executed. May be examined to control output formatting. Note that this word is reset by PAGE to 0.
  122.  
  123. #OUT
  124. A user variable which contains the number of characters TYPEd or EMITted since the last CR. Note that words such as SPACE or SPACES, which use EMIT, will also bump this variable. May be examined by the user to control output formatting. CR resets to 0.
  125.  
  126. DPL
  127. A user variable which contains the number of places after the decimal point for input conversion.
  128.  
  129. FENCE
  130. A user variable which contains the address below which FORGET will not operate. This may be changed by the user, but caution must be observed.
  131.  
  132. VIEW?
  133. A user variable which controls whether or not a view field will be compiled by CREATE. The view field is the field used by LOCATE to find the source code for definitions in the dictionary. If VIEW? is 0 , then no view field will be compiled. To compile view fields, VIEW? must contain a 2. Any other value will cause the system to behave oddly. Note that turning VIEW? off will save memory, but it does not affect execution speed. You should also be aware that executing SAVE-FORTH will save the current values of certain system variables, such as FENCE, VIEW?, WIDTH and WARNING.
  134.  
  135. WARNING
  136. A variable which controls the printing of non-fatal error messages (such as NAME ALREADY EXISTS). If warning is false, no messages will be printed.
  137.  
  138. WIDTH
  139. Controls the number of characters actually stored in the dictionary. The default is 31, which is specified by the Forth-83 standard. This may be changed by the user. Note that using fewer characters will save memory.
  140.  
  141. Although not variables, the following are used so often, this is probably a good place to tell you about them:
  142.  
  143. OFF
  144. Stores a false (0) in a variable. VARIABLENAME OFF is the same as FALSE VARIABLENAME ! , but much quicker.
  145.  
  146. ON
  147. Stores a true (-1) in a variable. VARIABLENAME ON is the same as TRUE VARIABLENAME ! , but much quicker.
  148.  
  149. MATH
  150.  
  151. (Note: The stack notation below uses n as an abbreviation for single numbers, and d to represent double numbers. Also note that floored division is used, to be consistant with the rest of the standard)
  152.  
  153. 2* ( n -- 2*n)
  154. Performs an arithmetic left shift of n, leaving the result on the top of the stack.
  155.  
  156. D2* ( d -- d*2)
  157. Same as 2* , but for double numbers.
  158.  
  159. M* ( n1 n2 -- d )
  160. D is the doublenumber product of the single numbers n1 n2.
  161.  
  162. M*/ ( d1 n1 n2 -- d2 )
  163. d2 is the result of multiplying d1 by n1 and dividing the resulting product by n2. An triple-precision intermediate product is used, and all values are signed.
  164.  
  165. M+ ( d1 n -- d2 )
  166. d2 is the sum of d1 and n. All values are signed.
  167.  
  168. M/ ( d1 n -- n2 n3)
  169. n3 is the remainder and n2 is the quotient of the division of d by n1. All values are signed.
  170.  
  171. M/MOD ( ud1 u1 -- u2 ud2 )
  172. ud2 is the quotient and u2 is the remainder of the division of ud1 by u1.
  173.  
  174. S>D ( n -- d )
  175. n is sign extended to form the double number d.
  176.  
  177. MISC:
  178.  
  179. ASCII
  180. A handy word. Used in the form 
  181. ASCII * 
  182. to either leave the ascii code for the following character on the top of the stack, or compile it as a literal for later execution. ASCII makes programs much more readable, and also saves much time spent looking up ascii codes in tables.
  183. *fp0
  184. CONTROL
  185. Also handy. Used in the form
  186. CONTROL "c"
  187. where c is one of the 64's weird reversed control characters, such as a cursor left or a clear screen.
  188.  
  189. FREE ( -- #bytes)
  190. Leaves the number of bytes free on the stack. This may be changed by CONFIGURE. (Note that the amount of memory occupied by the disk buffers is not considered FREE, although it may be used by user programs if no disk accesses are to be performed.)
  191.  
  192. //
  193. Causes the rest of the line to be viewed as a comment. Corresponds to a backslash, found on some computers, but, regrettably, not on the C64.
  194.  
  195. Blazin' Forth also includes Kim Harris's experimental proposals for dictionary operators. See the text of the Forth-83 standard for more information.
  196.  
  197. *lk:blazin.doc3
  198.